/*global __ENV__:true*/
import nattyFetch from 'natty-fetch-fd';
import NProgress from 'nprogress';

nattyFetch.on('reject',(res)=>{
    console.log(res);
});
/*初始化接口配置参数*/

const context = nattyFetch.context({
    mockUrlPrefix:'/',
    mock:!__ENV__,
    willFetch:()=>{
        NProgress.start();
    },
    data:()=>{
      return{
          'x-csrf-token':sessionStorage.getItem('token')
      };
    },
    didFetch:()=>{
        NProgress.done();
    },
    withCredentials:true,
    traditional:true,
    fit(respones) {
        console.log(respones);
        let flag = true;
        if(respones.status === "success") {
            flag = true;
        }else {
            flag = false;
        }
        return {
            'success':flag,
            'content':respones,
            'error':respones
        };
    }
});
const IO =context.api;
export {
    context,
    IO
};